package DataStructure;

/**
 * @author hanj.cn@outlook.com
 */
public class BubbleSort {

    public static void main(String[] args) {

        int[] array = {7, 6, 3, 2, 0, 9, 8, 4, 1, 5};
        int[] copy = {7, 6, 3, 2, 0, 9, 8, 4, 1, 5};

        int[] sortedArray = sort(array);

        show(copy, sortedArray);

    }

    private static int[] sort(int[] array) {

        int temp;
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = 0; j < array.length - 1 - i; j++) {
                if (array[j] > array[j + 1]) {
                    temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }
        return array;
    }

    private static void show(int[]... array) {

        System.out.print("原数组:\t");
        for (int num : array[0]) {
            System.out.printf("%d\t", num);
        }
        System.out.print("\n排序后:\t");
        for (int num : array[1]) {
            System.out.printf("%d\t", num);
        }
    }

}
